<template>
  <div class="container">
    <div class="information">
      <textarea rows="6"
                class="textarea"
                v-model="introduction"
                placeholder="    请粘贴客户，示例：
      客户姓名：张三
      客户性别：先生
      客户电话：17777755555
      意向楼盘：家喻户晓
      公司：巧房
      经纪人：李四
      经纪人电话：17777755555        "
                maxlength="800"></textarea>
      <div class="goInfoDetail">
        <div class="btn"
             @click="identification">智能识别</div>
        <div @click="()=>{$router.push({path:'/reportModel'})}">如何使用智能填写<i class="fa fa-angle-right iconRight"></i></div>
      </div>
    </div>
    <mt-field label="客户姓名："
              placeholder="请输入姓名(必填)"
              :attr="{ maxlength: 10 }"
              v-model="name"></mt-field>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">客户性别：</span>
        </div>
        <div class="mint-cell-value">
          <label class="sexBtn"
                 :class="{'active':checkedSex ==1}"
                 @click="checkedSex = 1">先生
            <input type="radio"
                   name="sex"
                   v-model="gender"
                   value="0" />
          </label>
          <label class="sexBtn"
                 :class="{'active':checkedSex ==2}"
                 @click="checkedSex = 2">女士
            <input type="radio"
                   name="sex"
                   v-model="gender"
                   value="1" />
          </label>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">客户电话：</span>
        </div>
        <div class="mint-cell-value"
             v-if="!isShow">
          <input type="tel"
                 placeholder="请输入电话(必填)"
                 class="mintPhone"
                 maxlength="11"
                 v-model="mobile"
                 @input="checkPhone" />
        </div>
        <div class="mint-cell-value"
             v-else>
          <input type="tel"
                 maxlength="8"
                 class="digital-input-box"
                 v-model="helfTel">
          <div class="digital-input">
            <template v-for="item of userTel">
              <div class="digital-input-item"
                   v-if="item!=='*'">{{ item }}</div>
              <div class="digital-input-item"
                   v-else><i class="fa fa-asterisk"></i></div>
            </template>
          </div>
        </div>
      </div>
    </div>
    <div class="mint-cell"
         v-if="reportType === '0'">
      <div class="mint-cell mint-field">
        <div class="mint-cell-wrapper">
          <div class="mint-cell-title">
            <span class="mint-cell-text"></span>
          </div>
          <div class="mint-cell-value">
            <div class="telEye"
                 @click="changeReportWay">
              <span class="toggleTel"
                    v-if="isShow">
                <i class="fa fa-eye-slash"></i>隐号报备
              </span>
              <span class="toggleTel"
                    v-if="!isShow">
                <i class="fa fa-eye"></i>全号报备
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">意向楼盘：</span>
        </div>
        <div class="mint-cell-value">
          <select class="selectPremises"
                  v-model="premisesId">
            <option value="0"
                    selected="selected">请选择楼盘</option>
            <option v-for="(item, index) in premisesList"
                    :value="item.premisesId"
                    :key="index">{{item.premisesName}}</option>
          </select>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field"
         v-if="visitProtectSwitchShow == '1'">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">到访延长时间：</span>
        </div>
        <div class="mint-cell-value">
          <span class="show-time">{{protectTime}}</span>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">最短报备时间：</span>
        </div>
        <div class="mint-cell-value">
          <span class="show-time">{{specialTime}}</span>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field"
         v-if="reportProtectType && reportProtectType != 4">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">报备保护时间：</span>
        </div>
        <div class="mint-cell-value">
          <div class="show-time"
               style="float: left;width: 100%;">
            <span>{{reportProtect}}</span>
          </div>
          <div style="text-align: right;"
               v-if="reportProtectTipImgFlag">
            <span @click="reportProtectTip(1)"><i class="fa fa-exclamation-circle warning-icon"></i></span>
          </div>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">公司：</span>
        </div>
        <div class="mint-cell-value">
          <input type="text"
                 name="jjr"
                 placeholder="请选择公司"
                 onfocus="this.blur();"
                 @click="showCompanyList()"
                 v-model="companyName"
                 readonly>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">经纪人：</span>
        </div>
        <div class="mint-cell-value">
          <input style="width: 80%;"
                 type="text"
                 name="jjr"
                 placeholder="请选择经纪人"
                 onfocus="this.blur();"
                 @click="showPartnerList"
                 v-model="accountName"
                 readonly>
          <button class="add-agent"
                  v-show="showAddAgentBtn"
                  @click="showAddAgentModel">新增</button>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field"
         v-show="accountMobile">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">经纪人电话：</span>
        </div>
        <div class="mint-cell-value">
          <input style="width: 80%;"
                 type="number"
                 v-model="accountMobile"
                 disabled>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field"
         v-if="visitTimeStatus && visitTimeStatus != 0">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">期望带看时间：</span>
        </div>
        <div class="mint-cell-value">
          <input type="text"
                 name="date"
                 @click="openPicker"
                 placeholder="请选择期望带看时间"
                 v-model="visitProtectDate"
                 readonly>
        </div>
      </div>
    </div>
    <div class="mint-cell mint-field"
         v-if="recommenderStatus && recommenderStatus != 0">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">报备推荐人：</span>
        </div>
        <div class="mint-cell-value">
          <input type="text"
                 name="jjr"
                 placeholder="请选择报备推荐人"
                 onfocus="this.blur();"
                 @click="showRecommenderList()"
                 v-model="recommendName"
                 readonly>
        </div>
      </div>
    </div>

    <div class="mint-cell mint-field"
         v-for="(r,index) in reportModelList"
         :key="index">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">{{r.modelColumn}}:</span>
        </div>
        <div class="mint-cell-value">
          <input type="text"
                 :placeholder="r.modelColumn"
                 v-model="r.content">
        </div>
      </div>
    </div>

    <div class="mint-cell mint-field is-textarea">
      <div class="mint-cell-wrapper">
        <div class="mint-cell-title">
          <span class="mint-cell-text">备注：</span>
        </div>
        <div class="mint-cell-value">
          <textarea rows="4"
                    class="mint-field-core"
                    v-model="remark"></textarea>
        </div>
      </div>
    </div>

    <div class="report-button">
      <mt-button size="large"
                 type="danger"
                 v-show="reportBtnShow"
                 @click="checkCustomerPremises">报备</mt-button>
    </div>

    <mt-popup v-model="popupCompany"
              position="bottom"
              class="mint-popup mint-datetime mint-popup-bottom">
      <div class="">
        <mt-picker :slots="addressSlots"
                   valueKey='agentCompanyName'
                   :item-height="48"
                   @change="onValuesChange"
                   :show-toolbar="true">
          <mt-button @click="showSearch"
                     style="font-family: mintui!important;width:15%"
                     class="mintui-search left"></mt-button>
          <mt-button @click="completeCompany"
                     class="mint-datetime-action sureBtn">确认</mt-button>
        </mt-picker>
      </div>
    </mt-popup>

    <mt-popup v-model="popupAgency"
              position="bottom"
              class="mint-popup mint-datetime mint-popup-bottom">
      <mt-picker :slots="agencySlots"
                 value-key="accountName"
                 :item-height="48"
                 @change="onAgencyChange"
                 :show-toolbar="true">
        <mt-button @click="showAgencySearch"
                   style="font-family: mintui!important;width:15%"
                   class="mintui-search left"></mt-button>
        <mt-button @click="completeAgency"
                   class="mint-datetime-action sureBtn">确认</mt-button>
      </mt-picker>
    </mt-popup>
    <mt-popup v-model="popupRecommender"
              position="bottom"
              class="mint-popup mint-datetime mint-popup-bottom">
      <mt-picker :slots="recommenderSlots"
                 value-key="userName"
                 :item-height="48"
                 @change="onRecommenderChange"
                 :show-toolbar="true">
        <mt-button @click="showRecommenderSearch"
                   style="font-family: mintui!important;width:15%"
                   class="mintui-search left"></mt-button>
        <mt-button @click="completeRecommender"
                   class="mint-datetime-action sureBtn">确认</mt-button>
      </mt-picker>
    </mt-popup>
    <!-- 状态变更备注 -->
    <div class="popup-page"
         v-if="addAgentModelShow">
      <div class="popup-mask"
           @click="closeAddAgentModel"></div>
      <div class="popup-container">
        <div class="popup-header"
             style="text-align: center; color: gray;">新增经纪人</div>
        <div class="popup-body">
          <ul class="invalid-list">
            <li style="padding-left: 0px; margin-bottom: 10px;">
              <label style="color: red">*</label>经纪人姓名&nbsp;
              <input type="text"
                     name="agentName"
                     v-model="addAgentModel.agentName"
                     placeholder="请输入经纪人姓名"
                     class="add-agent-input" />
            </li>
            <li style="padding-left: 0px; margin-bottom: 10px;">
              <label style="color: red">*</label>经纪人手机&nbsp;
              <input type="text"
                     name="agentPhone"
                     v-model="addAgentModel.agentPhone"
                     placeholder="请输入经纪人手机"
                     class="add-agent-input" />
            </li>
            <li style="padding-left: 0px; margin-bottom: 10px;">
              <label style="width: 100%; font-size: 12px; margin-left: 16%; color: gray;">手机号将作为经纪人登录系统的账号</label>
            </li>
          </ul>
        </div>
        <div class="popup-footer">
          <a href="javascript:;"
             class="btn"
             @click="closeAddAgentModel">取消</a>
          <a href="javascript:;"
             class="btn checkBtn"
             @click="addAgent">确定</a>
        </div>
      </div>
    </div>

    <!-- 匹配相似经纪人 -->
    <div class="popup-page"
         v-if="agentSimilar">
      <div class="popup-container"
           style="min-height: 230px;">
        <div class="popup-body">
          <div style="margin: 20px 0;">
            <p>
              根据系统匹配，发现有相似经纪人<br />
              <span>{{warnInfo}}</span>
            </p>
          </div>
          <div class="agent-warn">
            <ul>
              <li>姓名：{{agentInfo.name}}</li>
              <li>手机号：{{agentInfo.phone}}</li>
              <li>经纪公司：{{agentInfo.companyName}}</li>
            </ul>
          </div>
          <div class="agent-warn"
               v-if="!appointAgent"
               style="color:#f44336">
            但该机构无法报备该楼盘，请修改
          </div>
        </div>
        <div class="popup-footer">
          <a href="javascript:;"
             class="btn"
             v-bind:style="{width:btnWidth}"
             @click="agentSimilar = false;">返回修改</a>
          <a href="javascript:;"
             v-if="appointAgent"
             class="btn checkBtn"
             @click="confirmAgent">就是他</a>
        </div>
      </div>
    </div>
    <!-- reportProtectTip start -->
    <div class="reportProtectTipBack"
         v-if="reportProtectTipFlag"></div>
    <div class="reportProtectTip"
         v-if="reportProtectTipFlag">
      <span class="reportProtectTipContent"
            v-if="currentTip == '1'">
        <span class="redColor"
              style="font-size: 20px;font-weight: bold;">注意！</span><br />
        该客户在此楼盘下<br />
        存在<span class="redColor">{{reportProtectObj.count}}次</span>报备逾期未到访的记录<br />
        可能是您或您的同事未进行有效跟进<br />
        因此本次报备保护时间将缩短至<span class="redColor">{{reportProtectObj.msg}}</span><br />
        超过期限后，将允许其他经纪人报备<br />
        请及时跟进带看<br />
        避免再次逾期未到访
      </span>
      <span class="reportProtectTipContent"
            v-if="currentTip == '2'">
        <span class="redColor"
              style="font-size: 20px;font-weight: bold;">注意！</span><br />
        该客户在此楼盘下<br />
        存在<span class="redColor">{{reportProtectObj.count}}次</span>报备逾期未到访的记录<br />
        可能是您或您的同事未进行有效跟进<br />
        因此本次报备<span class="redColor">{{reportProtectObj.msg}}</span><br />
        将允许其他经纪人报备或带看<br />
        请及时跟进带看
      </span>
      <span class="reportProtectTipContent"
            v-if="currentTip == '3'">
        <span class="redColor"
              style="font-size: 20px;font-weight: bold;">注意！</span><br />
        该客户在此楼盘下<br />
        存在<span class="redColor">{{reportProtectObj.count}}次</span>报备逾期未到访的记录<br />
        可能是您或您的同事未进行有效跟进<br />
        因此本次已<span class="redColor">{{reportProtectObj.msg}}</span><br />
        请联系管理员处理
      </span>
      <span class="reportProtectTipContent"
            v-if="currentTip == '4'">
        <span class="redColor"
              style="font-size: 20px;font-weight: bold;">注意！</span><br />
        该客户在此楼盘下<br />
        存在<span class="redColor">{{reportProtectObj.count}}次</span>到访逾期未交易的记录<br />
        可能是您或您的同事未进行有效跟进<br />
        因此本次报备保护时间将缩短至<span class="redColor">{{reportProtectObj.msg}}</span><br />
        超过期限后，将允许其他经纪人报备<br />
        请及时跟进业务<br />
        避免再次逾期未交易
      </span>
      <span class="reportProtectTipContent"
            v-if="currentTip == '5'">
        <span class="redColor"
              style="font-size: 20px;font-weight: bold;">注意！</span><br />
        该客户在此楼盘下<br />
        存在<span class="redColor">{{reportProtectObj.count}}次</span>到访逾期未交易的记录<br />
        可能是您或您的同事未进行有效跟进<br />
        因此本次报备<span class="redColor">{{reportProtectObj.msg}}</span><br />
        将允许其他经纪人报备或带看<br />
        请及时跟进带看
      </span>
      <div class="tipBtn"
           @click="reportProtectTip(2)">好的</div>
    </div>
    <vant-popup v-model="popShow"
                position="bottom">
      <vant-datetime-picker v-model="pickerValue"
                            @confirm="handleConfirm"
                            @cancel="handleCancel"
                            ref="datePicker"
                            type="datetime" />
    </vant-popup>
  </div>
</template>

<script>
import {
  Toast,
  MessageBox,
  Popup,
  Search,
  DatetimePicker,
  CellSwipe,
  Picker
} from "mint-ui";
import "mint-ui/lib/style.css";
import VantPopup from "vant/lib/popup";
import VantDatetimePicker from "vant/lib/datetime-picker";
import "vant/lib/popup/style";
import "vant/lib/datetime-picker/style";
export default {
  components: { VantPopup, VantDatetimePicker },
  data() {
    return {
      visitProtectSwitchShow: "1", //默认展示
      name: "", //姓名
      gender: "0", //性别
      mobile: "", //电话
      remark: "", //备注
      checkedSex: 1,
      isShow: false,
      helfTel: "",
      companyList: [],
      premisesList: [],
      agentList: [],
      companyId: 0,
      premisesId: 0,
      agentId: 0,
      recommenderUuid: "",
      reportBtnShow: true,
      visitProtectDate: "",
      isSubmit: 0,
      pickerValue: new Date(),
      accountPopupVisible: false,
      companyPopupVisible: false,
      accountName: "",
      recommendName: "",
      companyName: "",
      popupCompany: false,
      popupAgency: false,
      popupRecommender: false,
      addressSlots: [],
      agencySlots: [],
      recommenderSlots: [],
      recommenderList: [],
      tempCompanyId: 0,
      tempCompanyName: "",
      tempAgencyId: 0,
      tempAgencyName: "",
      tempRecommenderId: "",
      tempRecommenderName: "",
      showAddAgentBtn: false,
      addAgentModelShow: false,
      addAgentModel: {
        agentCompany: "",
        agentName: "",
        agentPhone: ""
      },
      protectTime: "",
      specialTime: "",
      reportProtect: "",
      reportProtectType: "",
      reportProtectTipFlag: false,
      reportProtectTipImgFlag: false,
      reportProtectObj: null,
      reportProtectTipList: [],
      currentTip: 0,
      agentSimilar: false,
      agentInfo: { id: "", name: "", companyName: "" },
      warnInfo: "",
      appointAgent: true,
      btnWidth: "50%",
      visitTimeStatus: "1",
      recommenderStatus: "1",
      recommenderCheck: false,
      popShow: false,
      reportModelList: [],
      introduction: "",
      accountMobile: "",
      modelAccountComp: "",
      modelAccountName: "",
      modelRecommendName: "",
      hasAccountComp: false,
      hasRecommend: false,
      hasAccountName: false,
      userTel: "",
      reportType: "1",
      reportTypeName: "全号",
      copeyMobile: ""
    };
  },
  watch: {
    topPopup: function (val) {
      if (val) {
        setTimeout(() => {
          this.topPopup = false;
        }, 2000);
      }
    },
    premisesId: function (val) {
      this.premisesId = val;
      if (!val || val == 0) {
        return;
      }
      this.initCompanyList(val);
      this.initRecommenderList(val);
      this.companyName = "";
      this.accountName = "";
      this.companyId = null;
      this.agentId = null;
      this.getModelList();
      this.getDefaultModelList();
      //
      this.premisesList.forEach((item) => {
        if (item.premisesId == this.premisesId) {
          this.protectTime = this.setProtectTime(
            item.protectTime,
            item.protectTimeType
          );
          //this.specialTime = '提前' + item.specialTime + '分钟';
          this.specialTime =
            "提前" +
            this.setProtectTime(item.specialTime, item.specialTimeType);
          this.reportProtect = this.setProtectTime(
            item.reportProtect,
            item.reportProtectType
          );
          this.reportProtectType = item.reportProtectType;
          this.visitProtectSwitchShow = item.visitProtectSwitch;
          this.reportType = item.reportWay || "1";
          if (this.reportType === "1" || this.reportType === "0") {
            this.isShow = false;
          } else {
            this.isShow = true;
          }
          if (
            this.reportProtectType &&
            this.reportProtectType != 4 &&
            this.mobile &&
            this.mobile.length == 11
          ) {
            this.checkReportProtectConfig();
          }
        }
      });
    },
    companyId: function (newValue, oldValue) {
      if (this.companyId != null) {
        this.initAgencyList(newValue);
      }
    },
    mobile: function (val, oldVal) {
      // 全号提交
      if (!this.isShow) {
        if (val && val.length < 11) {
          this.reportProtectTipImgFlag = false;
          return;
        }
        //if(val && !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(val))){
        if (val && !/^(1|8)\d{10}$/.test(val)) {
          layer.msg("请输入正确的号码", {
            time: 2000
          });
          return false;
        }
        this.checkReportProtectConfig();
      }
      // else {
      //   // 隐号提交
      //   if (
      //     val &&
      //     (/^\d{11}$/.test(val) || /^(1|8)\d{2}\*{4}\d{4}/.test(val))
      //   ) {
      //     this.helfTel = `${val.substring(0, 3)}${val.substring(7)}`;
      //   } else {
      //     this.helfTel = "";
      //   }
      // }
    },
    reportType(v) {
      this.helfTel = "";
      if (this.reportType === "2") {
        this.userTel = `   ****    `;
      } else if (this.reportType === "3") {
        this.userTel = `    ****   `;
      } else if (this.reportType === "4") {
        this.userTel = `   ***     `;
      } else if (this.reportType === "5") {
        this.userTel = `  ***      `;
      } else if (this.reportType === "6") {
        this.userTel = `    ***    `;
      } else if (this.reportType === "0" || this.reportType === "1") {
        this.userTel = "";
        // this.mobile = "";
      }
    },
    helfTel(v) {
      const a = v.substring(0, 1) || " ";
      const b = v.substring(1, 2) || " ";
      const c = v.substring(2, 3) || " ";
      const d = v.substring(3, 4) || " ";
      const e = v.substring(4, 5) || " ";
      const f = v.substring(5, 6) || " ";
      const g = v.substring(6, 7) || " ";
      const h = v.substring(7, 8) || " ";
      if (this.reportType === "0") {
        this.userTel = `${a}${b}${c}****${d}${e}${f}${g}`;
      } else if (this.reportType === "2") {
        this.userTel = `${a}${b}${c}****${d}${e}${f}${g}`;
      } else if (this.reportType === "3") {
        this.userTel = `${a}${b}${c}${d}****${e}${f}${g}`;
      } else if (this.reportType === "4") {
        this.userTel = `${a}${b}${c}***${d}${e}${f}${g}${h}`;
      } else if (this.reportType === "5") {
        this.userTel = `${a}${b}***${c}${d}${e}${f}${g}${h}`;
      } else if (this.reportType === "6") {
        this.userTel = `${a}${b}${c}${d}***${e}${f}${g}${h}`;
      }
    },
    copeyMobile(v) {
      if (v) {
        this.helfTel = v;
        this.isShow = true;
      }
    }
  },
  mounted() {
    this.initPremisesList();
    this.initData();
    //this.initCompanyList(null);
  },
  activated() {
    //回退页面
    //this.initCompanyList(null);
    this.initPremisesList();
    this.popupCompany = false;
    if (this.$route.query.type == "1") {
      this.companyName = this.$route.query.companyName;
      this.companyId = this.$route.query.companyId;
      if (this.companyId) {
        this.showAddAgentBtn = true;
      }
      this.agentId = this.$route.query.agentId;
      this.accountName = this.$route.query.accountName;
    } else if (this.$route.query.type == "2") {
      this.agentId = this.$route.query.agentId;
      this.accountName = this.$route.query.accountName;
    }
  },
  beforeRouteEnter(to, from, next) {
    //如果是从首页过来的则初始化数据
    next((vm) => {
      if (from.path == "/index") {
        vm.initData();
      }
    });
  },
  methods: {
    checkPhone() {
      if (!this.premisesId) {
        layer.msg("请先选择意向楼盘", {
          time: 2000
        });
        this.mobile = "";
        return false;
      }
    },
    // 根据经纪人电话获取经纪人的公司和姓名，并自动填充
    async getAccountInfo() {
      const url = this.utilHelper.apiUrl + "/api/getAgentInfo";
      const body = {
        params: {
          userId: window.localStorage.getItem("2_userId"),
          companyUuid: window.localStorage.getItem("2_companyUuid"),
          phone: this.accountMobile
        }
      };
      this.$http.post(url, body).then((res) => {
        if (res.body.result == 1) {
          this.companyId = parseInt(res.body.resData.agentCompanyId) || null;
          this.companyName = res.body.resData.agentCompanyName || "";
          this.agentId = res.body.resData.partnerId || null;
          this.accountName = res.body.resData.partnerName || "";
        }
      });
    },
    // 清楚上一次的智能模板识别结果
    clearIdentification() {
      this.reportType = "1";
      this.reportTypeName = "全号";
      this.name = "";
      this.gender = "0";
      this.checkedSex = 1;
      this.mobile = "";
      this.helfTel = "";
      this.premisesId = 0;
      this.hasAccountComp = false;
      this.hasAccountName = false;
      this.hasRecommend = false;
      this.modelAccountComp = "";
      this.modelAccountName = "";
      this.modelRecommendName = "";
      this.accountMobile = "";
      this.visitProtectDate = "";
      this.remark = "";
      this.recommendName = "";
      this.recommenderUuid = "";
      this.companyId = null;
      this.companyName = "";
      this.agentId = null;
      this.accountName = "";
    },
    async identification() {
      this.clearIdentification();
      // 按规则分割成数组
      if (this.introduction && this.introduction.trim()) {
        let result = this.introduction.split(/[(\r\n)\r\n]+/);
        if (result && result.length) {
          result.forEach((item, i) => {
            result[i] = item.split(/:|：/);
            result[i] &&
              result[i].forEach((ele, j) => {
                result[i][j] = ele.trim();
              });
            // 时间时分也被冒号分隔，所以要合并处理
            if (result[i].length > 2) {
              result[i][1] = `${result[i][1]}:${result[i][2]}`;
              result[i].splice(2);
            }
          });
        }
        result &&
          result.find((item) => {
            if (Array.isArray(item)) {
              // 意向楼盘匹配成功再匹配其他字段，否则不做如何处理
              if ((item[0] === "意向楼盘" || item[0] === "楼盘") && item[1]) {
                let data =
                  this.premisesList &&
                  this.premisesList.find((ele) => ele.premisesName === item[1]);
                if (data) {
                  this.premisesId = data.premisesId;
                  // 先记录电话号码，然后又楼盘，按照该楼盘报备方式来处理电话号码
                  this.reportType = data.reportWay;
                  this.isShow =
                    this.reportType === "0" || this.reportType === "1"
                      ? false
                      : true;
                } else {
                  this.premisesId = 0;
                  this.reportType = "1";
                }
              }
            }
          });
        // 先匹配客户姓名、性别、电话和意向楼盘等字段名
        result &&
          result.forEach((item) => {
            if (Array.isArray(item)) {
              if (item[0] === "客户姓名" || item[0] === "姓名") {
                this.name = item[1] || "";
              }
              if (
                item[0] === "客户性别" ||
                item[0] === "客户类别" ||
                item[0] === "性别" ||
                item[0] === "类别"
              ) {
                if (["小姐", "女士", "女", "女生"].includes(item[1])) {
                  this.gender = "1";
                  this.checkedSex = 2;
                } else {
                  this.gender = "0";
                  this.checkedSex = 1;
                }
              }
              if (
                item[0] === "客户电话" ||
                item[0] === "客户手机号" ||
                item[0] === "客户手机号码"
              ) {
                if (this.reportType === "1") {
                  if (/^(1|8)\d{10}$/.test(item[1])) {
                    this.mobile = item[1];
                    this.isShow = false;
                  }
                } else if (this.reportType === "0") {
                  if (/^(1|8)\d{10}$/.test(item[1])) {
                    this.isShow = false;
                    this.mobile = item[1];
                  } else if (/^(1|8)\d{2}\*{4}\d{4}/.test(item[1])) {
                    this.copeyMobile =
                      item[1].substring(0, 3) + item[1].substring(7);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                } else if (this.reportType === "2") {
                  if (
                    /^(1|8)\d{2}\*{4}\d{4}/.test(item[1]) ||
                    /^(1|8)\d{10}$/.test(item[1])
                  ) {
                    this.copeyMobile =
                      item[1].substring(0, 3) + item[1].substring(7);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                } else if (this.reportType === "3") {
                  if (
                    /^(1|8)[\d]{3}[\*]{4}[\d]{3}$/.test(item[1]) ||
                    /^(1|8)\d{10}$/.test(item[1])
                  ) {
                    this.copeyMobile =
                      item[1].substring(0, 4) + item[1].substring(8);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                } else if (this.reportType === "4") {
                  if (
                    /^(1|8)[\d]{2}[\*]{3}[\d]{5}$/.test(item[1]) ||
                    /^(1|8)\d{10}$/.test(item[1])
                  ) {
                    this.copeyMobile =
                      item[1].substring(0, 3) + item[1].substring(6);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                } else if (this.reportType === "5") {
                  if (
                    /^(1|8)[\d]{1}[\*]{3}[\d]{6}$/.test(item[1]) ||
                    /^(1|8)\d{10}$/.test(item[1])
                  ) {
                    this.copeyMobile =
                      item[1].substring(0, 2) + item[1].substring(5);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                } else if (this.reportType === "6") {
                  if (
                    /^(1|8)[\d]{3}[\*]{3}[\d]{4}$/.test(item[1]) ||
                    /^(1|8)\d{10}$/.test(item[1])
                  ) {
                    this.copeyMobile =
                      item[1].substring(0, 4) + item[1].substring(7);
                    this.helfTel = this.copeyMobile;
                    this.isShow = true;
                  }
                }
              }
              if (item[0] === "经纪人公司" || item[0] === "公司") {
                this.hasAccountComp = item[1] ? true : false;
                this.modelAccountComp = item[1] || "";
              }
              if (item[0] === "经纪人姓名" || item[0] === "经纪人") {
                this.hasAccountName = item[1] ? true : false;
                this.modelAccountName = item[1] || "";
              }
              if (
                item[0] === "经纪人电话" ||
                item[0] === "经纪人手机号" ||
                item[0] === "经纪人手机号码"
              ) {
                this.accountMobile =
                  item[1] && /^(1|8)\d{10}$/.test(item[1]) ? item[1] : "";
              }
              if (item[0] === "期望带看时间") {
                const reg = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d)(:|：)[0-5]\d(:|：)[0-5]\d$/;
                const reg1 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d)(:|：)[0-5]\d$/;
                this.visitProtectDate =
                  item[1] &&
                  (new RegExp(reg).test(item[1]) ||
                    new RegExp(reg1).test(item[1]))
                    ? item[1]
                    : "";
              }
              if (item[0] === "报备推荐人") {
                this.hasRecommend = item[1] ? true : false;
                this.modelRecommendName = item[1] || "";
              }
              if (item[0] === "备注") {
                this.remark = item[1] || "";
              }
            }
          });
        // 意向楼盘匹配成功，再匹配后面的其他字段。否则，其他字段都不做处理
        if (this.premisesId) {
          // 匹配报备推荐人
          if (this.hasRecommend) {
            let recommenderList = await this.initRecommenderList(
              this.premisesId
            );
            let data =
              recommenderList &&
              recommenderList.find(
                (ele) => ele.userName === this.modelRecommendName
              );
            if (data) {
              this.recommendName = data.userName;
              this.recommenderUuid = data.recommenderUuid;
            } else {
              this.recommendName = "";
              this.recommenderUuid = "";
            }
          }
          // 匹配经纪人姓名和公司
          // 有经纪人电话，就匹配数据库返回的经纪人姓名和公司。没有再匹配模板写的经纪人姓名和公司

          if (this.accountMobile) {
            this.getAccountInfo();
          } else {
            // 没有经纪人电话，有经纪人公司则匹配模板的经纪人公司，匹配成功后，再判断如果有经纪人姓名就匹配经纪人姓名
            if (this.hasAccountComp) {
              let companyList = await this.initCompanyList(this.premisesId);
              const data =
                companyList &&
                companyList.find(
                  (ele) => ele.agentCompanyName === this.modelAccountComp
                );
              if (data) {
                this.companyId = data.agentCompany;
                this.companyName = data.agentCompanyName || "";
                if (this.hasAccountName) {
                  let agentList = await this.initAgencyList(this.companyId);
                  const datas =
                    agentList &&
                    agentList.find(
                      (ele) => ele.accountName === this.modelAccountName
                    );
                  if (datas) {
                    this.agentId = datas.id;
                    this.accountName = datas.accountName;
                  } else {
                    this.agentId = null;
                    this.accountName = "";
                  }
                }
              } else {
                this.companyId = null;
                this.companyName = "";
                this.agentId = null;
                this.accountName = "";
              }
            }
          }
        } else {
          this.recommendName = "";
          this.recommenderUuid = "";
          this.companyId = null;
          this.companyName = "";
          this.agentId = null;
          this.accountName = "";
        }
      }
    },
    reportProtectTip(type) {
      if (type == 1) {
        if (
          this.reportProtectTipList.length == 1 &&
          this.reportProtectTipList[0].code == "6"
        ) {
          layer.msg("该客户在此楼盘下已存在有效报备无法再次进行报备");
          return;
        }
        this.reportProtectObj = this.reportProtectTipList[0];
        this.currentTip = this.reportProtectObj.code;
        this.reportProtectTipFlag = true;
      } else {
        this.reportProtectTipFlag = false;
      }
    },
    checkReportProtectConfig() {
      // 本次这个不发
      return;

      var _self = this;
      if (!_self.premisesId) {
        return;
      }
      var body = {};
      body.params = {
        premisesId: _self.premisesId,
        cusPhoneList: [_self.mobile]
      };
      var url = _self.utilHelper.apiUrl + "/api/checkReportProtect";
      _self.$http.post(url, body).then((response) => {
        var body = response.body;
        var resData = body.resData;
        if (body.result == 1) {
          if (resData.list && resData.list.length > 0) {
            this.reportProtectTipList = resData.list;
            this.reportProtectTipImgFlag = true;
          } else {
            this.reportProtectTipImgFlag = false;
          }
        } else {
          this.reportProtectTipImgFlag = false;
          layer.msg("报备保护时间校验失败");
        }
      });
    },
    initCompanyList(premisesId) {
      let _self = this;
      let url = this.utilHelper.apiUrl + "/api/getAgentOrgByCompanyList";
      var body = {};
      body.params = {
        premisesId: _self.premisesId,
        pageNo: 1,
        pageSize: 50
      };
      return this.$http.post(url, body).then((response) => {
        let body = response.body;
        if (body.result == 1) {
          _self.companyList = [
            { agentCompanyId: "", agentCompanyName: "请选择公司" },
            ...body.resData.agentCompanyList
          ];
          this.addressSlots = [];
          this.addressSlots.push({ values: _self.companyList });
          return _self.companyList;
        } else {
          Toast({
            message: "数据获取失败",
            position: "middle",
            duration: 2000
          });
        }
      });
    },
    initAgencyList(companyId) {
      this.pageNo = 1;
      let url = this.utilHelper.apiUrl + "/api/getPartnerByAgentOrg";
      var body = {};
      body.params = {
        premisesId: this.premisesId,
        companyId: this.companyId,
        pageNo: 1,
        pageSize: 10
      };
      return this.$http.post(url, body).then((response) => {
        let body = response.body;
        if (body.result == 1) {
          this.agentList = [{ id: "", accountName: "请选择经纪人" }];
          for (var i = 0; i < body.resData.agentList.length; i++) {
            this.agentList.push(body.resData.agentList[i]);
          }
          this.agencySlots = [];
          this.agencySlots.push({ values: this.agentList });
          return this.agentList;
        } else {
          Toast({
            message: "数据获取失败",
            position: "middle",
            duration: 2000
          });
        }
      });
    },
    initRecommenderList(premisesId) {
      let _self = this;
      let url = this.utilHelper.apiUrl + "/api/premises/recommenders/list";
      var body = {};
      body.params = {
        id: this.premisesId
      };
      return this.$http.post(url, body).then((response) => {
        let body = response.body;
        if (body.result == 1) {
          this.recommenderList = [
            { recommenderUuid: "", userName: "请选择报备推荐人" },
            ...body.resData.list
          ];
          //清空之前的推荐人
          this.recommendName = "";
          this.recommenderUuid = "";
          if (body.resData.list && body.resData.list.length > 0) {
            _self.recommenderCheck = true;
            var loginUserId = window.localStorage.getItem("2_userId");
            //初始化报备推荐人
            for(var i = 0;i< body.resData.list.length; i++){
                if(body.resData.list[i].recommenderId == loginUserId){
                    this.recommendName = body.resData.list[i].userName
                    this.recommenderUuid = body.resData.list[i].recommenderUuid
                }
            }
          } else {
            _self.recommenderCheck = false;
          }
          this.recommenderSlots = [];
          this.recommenderSlots.push({ values: this.recommenderList });
          return this.recommenderList;
        } else {
          Toast({
            message: "数据获取失败",
            position: "middle",
            duration: 2000
          });
        }
      });
    },
    showRecommenderList: function () {
      //this.$router.push({path:'/reportSearch',query:{type:1}});
      if (!this.premisesId || this.premisesId == 0) {
        Toast("请选择意向楼盘");
        return;
      }
      this.popupRecommender = true;
      //替换方法
    },
    initPremisesList() {
      var body = {};
      //下架状态
      //销售状态为1:在售
      body.params = { saleStatus: 1 };
      var url = this.utilHelper.apiUrl + "/api/getCaseMemberList";
      this.$http.post(url, body).then((response) => {
        var body = response.body;
        if (1 == body.result) {
          this.premisesList = body.resData.caseMemberList;
        } else {
          Toast({
            message: "数据获取失败",
            position: "middle",
            duration: 2000
          });
        }
      });
    },
    reportUserInfo() {
      var _self = this;
      _self.reportBtnShow = false;
      if (this.verificationInfo()) {
        let url = this.utilHelper.apiUrl + "/api/agencyReport";
        if (this.isShow) {
          _self.mobile = _self.userTel;
        }
        var body = {};
        body.params = {
          name: _self.name,
          gender: _self.gender,
          mobile: _self.mobile,
          remark: _self.remark,
          staffId: _self.agentId,
          premisesId: _self.premisesId,
          isSubmit: _self.isSubmit,
          recommenderUuid: _self.recommenderUuid
        };
        if (_self.visitTimeStatus !== 0 && _self.visitProtectDate) {
          if (_self.visitProtectDate.split("/:|：/").length <= 2) {
            body.params.visitProtectDate = _self.visitProtectDate + ":00";
          }
        }
        var modelList = [];
        //报备模板列表
        for (var r in _self.reportModelList) {
          if (!_self.reportModelList[r].content) {
            layer.msg("请填写" + _self.reportModelList[r].modelColumn);
            _self.reportBtnShow = true;
            return;
          }
          modelList.push({
            modelId: _self.reportModelList[r].id,
            modelColumn: _self.reportModelList[r].modelColumn,
            content: _self.reportModelList[r].content
          });
        }
        body.params.reportModelList = modelList;
        this.$http.post(url, body).then((response) => {
          let body = response.body;
          //如果是2的话，代表重复点击，则不进行任何操作
          if (body.code == 2) {
            return;
          }
          if (body.result == 1) {
            if (!body.errorMsg) {
              let instance = Toast("提交成功");
              setTimeout(() => {
                _self.name = "";
                _self.gender = 0;
                _self.mobile = "";
                _self.remark = "";
                _self.premisesId = 0;
                _self.companyId = 0;
                _self.agentId = 0;
                _self.recommenderUuid = "";
                _self.visitProtectDate = "";
                _self.addAgentModel.agentCompany = "";
                _self.addAgentModel.agentName = "";
                _self.addAgentModel.agentPhone = "";
                _self.showAddAgentBtn = false;
                instance.close();
                _self.$router.push({
                  path: "/customerDetails"
                });
              }, 2000);
            } else {
              layer.msg(body.errorMsg, { area: "80%", time: 3000 });
              _self.reportBtnShow = true;
            }
          } else {
            if (body.errorCode == "9527") {
              var errorMsg =
                "本楼盘的到访延长时间为" +
                body.errorMsg +
                "分钟，从报备之时起" +
                body.errorMsg +
                "分钟内未到访," +
                "需要重新报备。您的期望带看时间已超过了到访延长时间，是否继续报备";
              MessageBox.confirm(errorMsg).then(
                (action) => {
                  //确定
                  _self.isSubmit = 1;
                  _self.reportUserInfo();
                },
                (action) => {
                  //取消
                  _self.reportBtnShow = true;
                }
              );
              return false;
            }
            Toast({
              message: "报备失败:" + body.resData.resultMsg,
              position: "middle",
              duration: 2000
            });
            _self.reportBtnShow = true;
          }
        });
      } else {
        _self.reportBtnShow = true;
      }
    },
    checkMobile(reportWay) {
      let mobileRight = true;
      if (reportWay === "2") {
        this.reportTypeName = "前三后四";
        mobileRight = /^(1|8)\d{2}\*{4}\d{4}/.test(this.userTel) ? true : false;
      } else if (reportWay === "3") {
        this.reportTypeName = "前四后三";
        mobileRight = /^(1|8)[\d]{3}[\*]{4}[\d]{3}$/.test(this.userTel)
          ? true
          : false;
      } else if (reportWay === "4") {
        this.reportTypeName = "前三后五";
        mobileRight = /^(1|8)[\d]{2}[\*]{3}[\d]{5}$/.test(this.userTel)
          ? true
          : false;
      } else if (reportWay === "5") {
        this.reportTypeName = "前二后六";
        mobileRight = /^(1|8)[\d]{1}[\*]{3}[\d]{6}$/.test(this.userTel)
          ? true
          : false;
      } else if (reportWay === "6") {
        this.reportTypeName = "前四后四";
        mobileRight = /^(1|8)[\d]{3}[\*]{3}[\d]{4}$/.test(this.userTel)
          ? true
          : false;
      } else if (reportWay === "0") {
        this.reportTypeName = "全号/前三后四";
        mobileRight = /^(1|8)[\d]{2}[\*]{4}[\d]{4}$/.test(this.userTel)
          ? true
          : false;
      }
      return mobileRight;
    },
    verificationInfo() {
      let _self = this;
      if (!this.name.trim()) {
        Toast({
          message: "请输入客户姓名",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      if (this.isShow) {
        //报备人手机号码必须和该楼盘的报备方式一致
        if (!this.checkMobile(this.reportType)) {
          Toast({
            message: `所选楼盘要求${this.reportTypeName}，请修改号码后提交`,
            position: "middle",
            duration: 3000
          });
          return false;
        }
      } else {
        //if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.mobile))){
        if (!/^(1|8)\d{10}$/.test(this.mobile)) {
          Toast({
            message: "客户电话有误或为空",
            position: "middle",
            duration: 3000
          });
          return false;
        }
      }
      if (
        (!this.premiseId && this.premiseId == 0) ||
        this.premisesId === undefined
      ) {
        Toast({
          message: "请选择意向楼盘",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      if (!this.companyName) {
        Toast({
          message: "请选择经纪公司",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      if (!this.agentId || this.agentId == 0) {
        Toast({
          message: "请选择经纪人",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      var visitProtectDate = _self.visitProtectDate;
      if (visitProtectDate == "" && _self.visitTimeStatus == 1) {
        Toast({
          message: "请选择期望带看时间",
          position: "middle",
          duration: 2000
        });
        return false;
      }
      if (
        _self.recommenderStatus == 1 &&
        _self.recommenderCheck &&
        !_self.recommenderUuid
      ) {
        Toast({
          message: "请选择报备推荐人",
          position: "middle",
          duration: 2000
        });
        return false;
      }

      return true;
    },
    openPicker() {
      this.popShow = true;
      // this.$refs.picker.open();
    },
    handleConfirm(e) {
      var date = new Date(e);
      var visitProtectDate =
        date.getFullYear() +
        "-" +
        this.fomrtDate(date.getMonth() + 1) +
        "-" +
        this.fomrtDate(date.getDate()) +
        " " +
        this.fomrtDate(date.getHours()) +
        ":" +
        this.fomrtDate(date.getMinutes());
      this.visitProtectDate = visitProtectDate;
      this.popShow = false;
    },
    handleCancel() {
      this.popShow = false;
    },
    fomrtDate(n) {
      return n >= 10 ? n : "0" + n;
    },
    showCompanyList: function () {
      //this.$router.push({path:'/reportSearch',query:{type:1}});
      if (!this.premisesId || this.premisesId == 0) {
        Toast("请选择意向楼盘");
        return;
      }
      this.popupCompany = true;
      //替换方法
    },
    showSearch: function () {
      this.$router.push({
        path: "/reportSearch",
        query: { type: 1, premiseId: this.premisesId }
      });
    },
    showAgencySearch: function () {
      this.popupAgency = false;
      this.$router.push({
        path: "/reportSearch",
        query: {
          type: 2,
          companyId: this.companyId,
          companyName: this.companyName
        }
      });
    },
    showRecommenderSearch: function () {
      this.$router.push({
        path: "/reportSearch",
        query: { type: 1, premiseId: this.premisesId }
      });
    },
    showPartnerList: function () {
      if (this.companyId == null || this.companyId == "") {
        Toast("请选择公司");
        return;
      } else {
        this.popupAgency = true;
        //this.$router.push({path:'/reportSearch',query:{type:2,companyId:this.companyId,companyName:this.companyName}});
      }
    },
    selectCompany: function (item) {
      this.companyName = item.agentCompanyName;
      this.companyId = item.agentCompany;
      this.popupCompany = false;
    },
    substring: function (value, size) {
      if (value.length > size) {
        return value.substring(0, size) + "...";
      } else {
        return value;
      }
    },
    changeReportWay() {
      this.isShow = !this.isShow;
      // 隐号
      if (this.isShow) {
        if (this.mobile) {
          const a = this.mobile.substring(0, 1) || "";
          const b = this.mobile.substring(1, 2) || "";
          const c = this.mobile.substring(2, 3) || "";
          const d = this.mobile.substring(7, 8) || "";
          const e = this.mobile.substring(8, 9) || "";
          const f = this.mobile.substring(9, 10) || "";
          const g = this.mobile.substring(10, 11) || "";
          this.helfTel = `${a}${b}${c}${d}${e}${f}${g}`;
        } else {
          this.helfTel = "";
          this.userTel = `   ****    `;
        }
      }
    },
    onValuesChange(picker, values) {
      var _self = this;
      if (values.length > 0) {
        _self.showAddAgentBtn = false;
        _self.tempCompanyId = values[0].agentCompany;
        if (_self.tempCompanyId) {
          _self.showAddAgentBtn = true;
        }
        _self.tempCompanyName = values[0].agentCompanyName;
      } else {
        _self.showAddAgentBtn = false;
      }
    },
    onAgencyChange(picker, values) {
      if (values.length > 0) {
        this.tempAgencyId = values[0].id;
        this.tempAgencyName = values[0].accountName;
      }
    },
    onRecommenderChange(picker, values) {
      if (values.length > 0) {
        this.tempRecommenderId = values[0].recommenderUuid;
        this.tempRecommenderName = values[0].userName;
      }
    },
    completeCompany() {
      if (!this.tempCompanyId) {
        this.companyId = null;
        this.companyName = "";
      } else {
        if (this.companyId != this.tempCompanyId) {
          this.companyId = this.tempCompanyId;
          this.companyName = this.tempCompanyName;
          //经纪人清空,本地参数清空，url清空
          this.agentId = null;
          this.accountName = "";
          this.$route.query.accountName = "";
        }
      }
      this.popupCompany = false;
    },
    completeAgency() {
      //经纪人选择
      if (!this.tempAgencyId) {
        this.agentId = null;
        this.accountName = "";
      } else {
        if (this.agentId != this.tempAgencyId) {
          this.agentId = this.tempAgencyId;
          this.accountName = this.tempAgencyName;
        }
      }
      this.popupAgency = false;
    },
    completeRecommender() {
      //报备推荐人选择
      if (!this.tempRecommenderId) {
        this.recommenderUuid = "";
        this.recommendName = "";
      } else {
        if (this.recommenderUuid != this.tempRecommenderId) {
          this.recommenderUuid = this.tempRecommenderId;
          this.recommendName = this.tempRecommenderName;
        }
      }
      this.popupRecommender = false;
    },
    showAddAgentModel() {
      var _self = this;
      if (!this.premisesId || this.premisesId == 0) {
        Toast("请选择意向楼盘");
        return;
      }
      _self.addAgentModelShow = true;
    },
    closeAddAgentModel() {
      var _self = this;
      _self.addAgentModelShow = false;
    },
    addAgent() {
      var _self = this;
      _self.addAgentModel.agentCompany = _self.companyId;
      _self.addAgentModel.premisesId = _self.premisesId;

      if (_self.verificationAddAgentInfo()) {
        var body = {};
        body.params = _self.addAgentModel;
        var url = this.utilHelper.apiUrl + "/api/addPartnerQuick";
        this.$http.post(url, body).then((response) => {
          var body = response.body;
          var resData = body.resData;
          if (1 == resData.result) {
            if (resData.existAgent == 1) {
              _self.afterAddAgent(resData);
              return;
            }

            _self.closeAddAgentModel();
            _self.tempAgencyId = resData.agentId;
            _self.tempAgencyName = resData.agentName;
            _self.agentId = _self.tempAgencyId;
            _self.accountName = _self.tempAgencyName;
          } else {
            Toast({
              message: resData.resultMsg,
              position: "middle",
              duration: 2000
            });
          }
        });
      }
    },
    checkCustomerPremises() {
      var _self = this;
      if (_self.verificationInfo()) {
        if (_self.visitTimeStatus !== 0 && _self.visitProtectDate) {
          _self.timesChange("save");
        } else {
          _self.reportUserInfo();
        }
      }
    },
    timesChange(type) {
      var _self = this;
      var timeStr = _self.visitProtectDate;
      if (timeStr) {
        var url = _self.utilHelper.apiUrl + "/api/isInSpecialTime";
        if (!_self.premisesId) {
          return;
        }
        var body = {};
        body.params = { hopeTime: timeStr, premisesId: _self.premisesId };
        _self.$http.post(url, body).then((response) => {
          var data = response.body.resData;
          var time = data.specialTime;
          var msg = data.msg;
          var saveDays = data.saveDays;
          if (data.result == 1) {
            if (msg == "1") {
              //特殊报备
              layer.confirm(
                "您的报备时间距离期望带看时间不足" +
                  time +
                  "分钟，请修改期望带看时间",
                {
                  btn: ["修改带看时间", "取消"], //按钮
                  shade: false //不显示遮罩
                },
                function () {
                  layer.closeAll();
                },
                function () {
                  layer.closeAll();
                }
              );
            } else if (msg == "2") {
              if (type && type == "save") {
                _self.reportUserInfo();
              }
            } else if (msg == "3") {
              layer.alert("您选择的时间必须大于系统当前时间");
            } else if (msg == "4") {
              layer.confirm(
                "本楼盘的到访延长时间为" +
                  saveDays +
                  "分钟，从报备之时起" +
                  saveDays +
                  "分钟内未到访，需要重新报备，您的期望带看时间已超过了到访延长时间",
                {
                  btn: ["修改带看时间", "没关系，届时再报备"], //按钮
                  shade: false //不显示遮罩
                },
                function () {
                  layer.closeAll();
                },
                function () {
                  if (type && type == "save") {
                    _self.reportUserInfo();
                  }
                  layer.closeAll();
                }
              );
            }
          } else {
            layer.msg(data.resultMsg);
          }
        });
      }
    },
    verificationAddAgentInfo() {
      let _self = this;
      if (!_self.companyId) {
        Toast({
          message: "请选择经纪公司",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      if (!_self.addAgentModel.agentName) {
        Toast({
          message: "请输入经纪人姓名",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(_self.addAgentModel.agentPhone)) {
        Toast({
          message: "经纪人电话有误或为空",
          position: "middle",
          duration: 3000
        });
        return false;
      }
      return true;
    },
    initData: function () {
      this.name = ""; //姓名
      this.gender = "0"; //性别
      this.mobile = ""; //电话
      this.remark = ""; //备注
      this.checkedSex = 1;
      this.isShow = false;
      this.helfTel = "";
      this.companyList = [];
      this.agentList = [];
      this.companyId = 0;
      this.agentId = 0;
      this.premisesId = 0;
      this.reportBtnShow = true;
      this.visitProtectDate = "";
      this.isSubmit = 0;
      this.pickerValue = new Date();
      this.accountPopupVisible = false;
      this.companyPopupVisible = false;
      this.accountName = "";
      this.companyName = "";
      this.popupCompany = false;
      this.addressSlots = [];
      this.tempCompanyId = 0;
      this.tempCompanyName = "";
      this.addAgentModel.agentCompany = "";
      this.addAgentModel.agentName = "";
      this.addAgentModel.agentPhone = "";
      this.showAddAgentBtn = false;
      this.protectTime = "";
      this.specialTime = "";
      this.recommenderUuid = "";
    },
    setProtectTime(time, type) {
      if (type == "1") {
        return time / 1440 + "天";
      } else if (type == 2) {
        return time / 60 + "小时";
      }
      return time + "分钟";
    },
    getModelList() {
      var _self = this;
      var url = this.utilHelper.apiUrl + "/api/getReportModelList";
      var body = {};
      body.params = { premisesId: _self.premisesId, modelType: 2 };
      _self.$http.post(url, body).then((response) => {
        var body = response.body;
        if (body.result == "1") {
          _self.reportModelList = body.resData.list;
        } else {
          layer.msg("获取报备模板失败");
        }
        this.$forceUpdate();
      });
    },
    getDefaultModelList() {
      var _self = this;
      var url = this.utilHelper.apiUrl + "/api/getReportModelList";
      var body = {};
      body.params = { premisesId: _self.premisesId, modelType: 1 };
      _self.$http.post(url, body).then((response) => {
        var body = response.body;
        if (body.result == "1") {
          var reportDefaultModelList = body.resData.list;
          if (reportDefaultModelList && reportDefaultModelList.length > 0) {
            for (var r in reportDefaultModelList) {
              if (reportDefaultModelList[r].modelColumn === "预计到访时间") {
                _self.visitTimeStatus = reportDefaultModelList[r].showFlag;
              }
              if (reportDefaultModelList[r].modelColumn === "报备推荐人") {
                _self.recommenderStatus = reportDefaultModelList[r].showFlag;
              }
            }
          }
        } else {
          layer.msg("获取报备模板失败");
        }
      });
    },
    afterAddAgent(resData) {
      //查询是重复的经纪人
      var _self = this;
      _self.agentSimilar = true;
      _self.agentInfo = {
        id: resData.agentId,
        name: resData.agentName,
        phone: resData.agentPhone,
        companyName: resData.companyName,
        companyId: resData.agentCompany
      };
      _self.warnInfo = "";
      //提示语判断 姓名，手机号，公司
      if (_self.addAgentModel.agentName == resData.agentName) {
        _self.warnInfo += "姓名、";
      }
      if (_self.addAgentModel.agentPhone == resData.agentPhone) {
        _self.warnInfo += "手机号、";
      }
      if (_self.companyId == resData.agentCompany) {
        _self.warnInfo += "公司";
      }
      if (_self.warnInfo) {
        if (_self.warnInfo.charAt(_self.warnInfo.length - 1) == "、") {
          _self.warnInfo = _self.warnInfo.substring(
            0,
            _self.warnInfo.length - 1
          );
        }
        _self.warnInfo += "相同";
      }
      if (resData.appointAgent == 0) {
        _self.appointAgent = false;
        _self.btnWidth = "100%";
      }
    },
    confirmAgent() {
      var _self = this;
      _self.tempAgencyId = _self.agentInfo.id;
      _self.tempAgencyName = _self.agentInfo.name;
      _self.agentId = _self.agentInfo.id;
      _self.accountName = _self.agentInfo.name;
      _self.agentSimilar = false;
      _self.companyName = _self.agentInfo.companyName;
      //todo 下拉列表数据定位
      _self.closeAddAgentModel();
    }
  }
};
</script>
<style scoped lang="less">
.information {
  display: flex;
  flex-direction: column;
  padding-bottom: 10px;
  .textarea {
    padding: 10px;
    font-size: 16px;
    width: 100%;
  }
  .goInfoDetail {
    text-align: right;
    font-size: 14px;
    background: #fff;
    padding: 10px;
    color: #a9a9a9;
    display: flex;
    justify-content: space-between;
    .btn {
      width: 75px;
      height: 25px;
      line-height: 25px;
      text-align: center;
      background-color: #ec6f26;
      color: #fff;
      border-radius: 20px;
    }
    .iconRight {
      margin-left: 10px;
    }
  }
}
.redColor {
  color: #ff5e5e;
}
.mint-field .mint-cell-title {
  color: #000;
  width: 115px;
}
.mint-cell-value .sexBtn {
  width: 56px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid #cdcdcd;
  text-align: center;
  line-height: 22px;
  font-size: 12px;
  margin: 0 4px;
}
.mint-cell-value .sexBtn.active {
  border: 1px solid #eb6100;
  color: #eb6100;
  background-color: #ffece0;
}
.sexBtn input {
  display: none;
}
.telEye {
  color: #ec6f26;
  position: absolute;
  right: 10px;
  display: inline-block;
}
.toggleTel .fa {
  margin-right: 6px;
}
.digital-input-box {
  position: absolute;
  opacity: 0.01;
  display: block;
  z-index: 50;
  left: 115px;
  width: 100%;
  top: 2px;
  height: 46px;
}
.digital-input {
  overflow: hidden;
  width: 100%;
}
.digital-input .digital-input-item {
  height: 48px;
  float: left;
  width: 9.09%;
  border-right: 1px dashed #d8d8d8;
  text-align: center;
  line-height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.digital-input .digital-input-item:first-child {
  border-left: 1px solid #d8d8d8;
}
.digital-input-item .fa {
  font-size: 12px;
  color: #999;
}
.mint-field.is-textarea .mint-cell-wrapper .mint-cell-text {
  position: absolute;
  top: 12px;
}
.report-button {
  padding: 0 10px;
}
.report-button .mint-button--danger {
  background-color: #eb6100;
  margin-top: 20px;
}
.digital-input:after {
  content: "";
  display: block;
  clear: both;
  visibility: hidden;
  overflow: hidden;
  font-size: 0;
  height: 0;
}

.operation-btn {
  padding: 6px 10px;
  background-color: #fffef6;
  border-top: 1px solid #cdcdcd;
  position: fixed;
  bottom: 0;
  display: block;
  width: 100%;
}
.operation-btn .operation-btn-link {
  width: 50%;
  float: left;
  text-align: center;
  height: 24px;
  line-height: 24px;
  border-right: 1px solid #cdcdcd;
  color: #eb6100;
  font-size: 14px;
}
.operation-btn .operation-btn-link:last-child {
  border-right: none;
}
.operation-btn:after {
  content: "";
  display: block;
  clear: both;
  visibility: hidden;
  overflow: hidden;
  font-size: 0;
  height: 0;
}
.mint-popup-2 {
  width: 100%;
  height: 50px;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.7);
  backface-visibility: hidden;
}
.mint-popup-2 p {
  line-height: 50px;
  color: #fff;
}
.company-li {
  line-height: 30px;
}
.arrow-top {
  width: 20px;
  height: 20px;
  border-color: #26a2ff;
  border-width: 0 0 2px 2px;
  border-style: solid;
  transform: rotateZ(-45deg);
  margin: 0 0 0 10px;
}
.arrow-down {
  width: 20px;
  height: 20px;
  border-color: #26a2ff;
  border-width: 2px 2px 0 0;
  border-style: solid;
  transform: rotateZ(-45deg);
  margin: 12px 0 0 25px;
}
.left {
  float: left;
}

/*弹出层*/
.popup-page,
.popup-mask {
  position: fixed;
  z-index: 99;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.popup-mask {
  background-color: #000;
  opacity: 0.3;
}
.popup-container {
  width: 300px;
  position: relative;
  background-color: #fff;
  top: 160px;
  left: 44%;
  margin-left: -130px;
  z-index: 100;
  border-radius: 6px;
}
.popup-header {
  padding: 12px 20px;
  border-bottom: 1px solid #cdcdcd;
}
.popup-body {
  padding: 16px 20px 10px;
}
.popup-footer {
  width: 100%;
  border-top: 1px solid #cdcdcd;
}
.popup-footer .btn {
  width: 50%;
  text-align: center;
  float: left;
  padding: 12px 0;
  font-size: 16px;
  color: #999;
}
.popup-footer .checkBtn {
  color: #eb6100;
}
.popup-footer .btn:first-child {
  border-right: 1px solid #cdcdcd;
}
.popup-footer:after {
  content: "";
  display: block;
  clear: both;
  visibility: hidden;
  overflow: hidden;
  font-size: 0;
  height: 0;
}

.add-agent {
  width: 50px;
  height: 30px;
  line-height: 20px;
  text-align: center;
  background: #ec6f26;
  color: #fff;
  border-radius: 3px;
}

.add-agent-input {
  /* width: 67%;  */
  width: 65%;
  height: 28px;
  border-radius: 3px;
  border: 1px solid gray;
}
.add-agent-input:focus {
  border: 1px solid #f87242;
}
.show-time {
  color: #ec6f26;
}
.agent-warn {
  margin: 20px 0;
}
.agent-warn ul li {
  color: #eb6100;
}

.reportProtectTipBack {
  background: #000;
  opacity: 0.5;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
}
.tipsCountStyle {
  position: absolute;
  left: 45vw;
  top: 68vh;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  width: 10vw;
  text-align: center;
}
.reportProtectTip {
  position: absolute;
  z-index: 999;
  top: 22vh;
  left: 16.5vw;
  width: 67vw;
  height: 44vh;
  line-height: 4vh;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 3vw;
  background: #fff;
  font-size: 3.5vw;
}
.reportProtectTip .tipBtn {
  width: 60.5vw;
  height: 9vw;
  line-height: 9vw;
  background: #ff5e5e;
  color: #fff;
  text-align: center;
  border-radius: 3px;
  position: absolute;
  bottom: 3vw;
}
.warning-icon {
  font-size: 20px;
  color: #ff5e5e;
}
.sureBtn {
  width: 85%;
}
</style>
<style>
.picker-items {
  width: 100% !important;
}
</style>

